home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 October / macformat-108.iso / Shareware / Math scientific / PsyScript / libraries / stairCase.lib / stairCase.lib.rsrc / TEXT_2000_Source Text.txt < prev    next >
Encoding:
Text File  |  2001-05-14  |  4.6 KB  |  133 lines

  1. property pMyName : ""
  2. property pParameters : {maxreversals:0, maxtrials:0, stepSize:1, initialDuration:10}
  3. property pStairCaseRecord : {currentDuration:10, history:{-1, -1, -1}, reversals:0, directionList:{}, trialCount:0}
  4. --currentDuration = the variable being staircased.    
  5. --history: a  history as deep as is needed 
  6. -- reversals: count of reversals
  7. --directionList: history of directions
  8. --valid directions = "up"  "down" and "none"
  9. --trialCount: speaks for itself                    
  10. --assumptions: that you run the duration that it gives you        
  11.  
  12. to initialize(nameString, pars) --pars must be a valid parameter record, i.e., {maxreversals:5, maxtrials:3, stepSize:1, initialDuration:10}
  13.     --try
  14.     set pMyName to nameString
  15.     iInitializeStairCaseRecord()
  16.     iSetParameters(pars)
  17.     set currentDuration of pStairCaseRecord to initialDuration of pParameters
  18. end initialize
  19.  
  20. to update(gradedResponse) --0 if wrong, 1 if correct
  21.     --update history and trial count
  22.     set trialCount of pStairCaseRecord to (trialCount of pStairCaseRecord) + 1
  23.     set gradedResponse to gradedResponse as integer
  24.     iUpDateResponseHistory(gradedResponse)
  25.     set last2responses to items 2 thru 3 of history of pStairCaseRecord
  26.     
  27.     if gradedResponse = 0 then
  28.         iHandleShift("up") --one wrong, so shift up
  29.     else if last2responses = {1, 1} then
  30.         iHandleShift("down") --that's three correct in a row, so shift down
  31.     else
  32.         iHandleShift("none") --no shift, but update the history
  33.     end if
  34.     return currentDuration of pStairCaseRecord
  35.     (* on error
  36.             error "update failed"
  37.         end try *)
  38. end update
  39.  
  40. to updateStepSize(newStep)
  41.     set stepSize of pParameters to newStep
  42. end updateStepSize
  43.  
  44. on getRecord()
  45.     return pStairCaseRecord
  46. end getRecord
  47.  
  48. on getParameters()
  49.     return pParameters
  50. end getParameters
  51.  
  52. on getParametersAsSpreadsheetText()
  53.     return {{pMyName & " maxreversals", maxreversals of pParameters}, ¬¨
  54.         {pMyName & " maxtrials", maxtrials of pParameters}, ¬¨
  55.         {pMyName & " stepSize", stepSize of pParameters}, ¬¨
  56.         {pMyName & " initialDuration", initialDuration of pParameters}}
  57. end getParametersAsSpreadsheetText
  58.  
  59.  
  60. --be sure and synch any changes here with the getrtrialdata handler
  61. on getTrialDataHeaderLineAsSpreadsheetText()
  62.     return {"stairName", "thisTrialcount", "thisDuration", "correct response", "thisSubjectResponse", "thisGradedResponse", "thisRT"}
  63. end getTrialDataHeaderLineAsSpreadsheetText
  64.  
  65. on getTrialData(subjectResponse, correctResponse)
  66.     tell application "PsyScript"
  67.         if (subjectResponse = correctResponse) then
  68.             set thisGradedResponse to 1
  69.         else
  70.             set thisGradedResponse to 0
  71.         end if
  72.         set theRt to get reaction time
  73.         set thisTrialcount to trialCount of my getRecord()
  74.         set thisDuration to currentDuration of pStairCaseRecord
  75.         return {pMyName:pMyName, thisTrialcount:thisTrialcount, thisDurationt:thisDuration, correctResponse:correctResponse, subjectResponset:subjectResponse, thisGradedResponse:thisGradedResponse, thisRT:theRt}
  76.     end tell
  77. end getTrialData
  78.  
  79.  
  80. on completed()
  81.     if ((reversals of pStairCaseRecord ‚â• maxreversals of pParameters) or (trialCount of pStairCaseRecord ‚â• maxtrials of pParameters)) then
  82.         return true
  83.     else
  84.         return false
  85.     end if
  86. end completed
  87.  
  88. --should never need to call these handlers (they start with an "i" for "internal use only"
  89.  
  90.  
  91. to iSetParameters(pars)
  92.     set pParameters to pars
  93. end iSetParameters
  94.  
  95.  
  96. to iInitializeStairCaseRecord()
  97.     set pStairCaseRecord to {currentDuration:0, history:{-1, -1, -1}, reversals:0, directionList:{}, trialCount:0}
  98. end iInitializeStairCaseRecord
  99.  
  100. to iUpDateResponseHistory(gradedResponse)
  101.     set beginning of history of pStairCaseRecord to gradedResponse
  102. end iUpDateResponseHistory
  103.  
  104. to iInitializeResponseHistory()
  105.     set history of pStairCaseRecord to {-1, -1, -1}
  106. end iInitializeResponseHistory
  107.  
  108. to iHandleShift(direction)
  109.     --try
  110.     set end of directionList of pStairCaseRecord to direction
  111.     if trialCount of pStairCaseRecord ‚â§ 2 then
  112.         -- there is no history yet
  113.     else if direction ‚↠item -2 of directionList of pStairCaseRecord then
  114.         set reversals of pStairCaseRecord to (reversals of pStairCaseRecord) + 1
  115.     end if -- no need to update reversals
  116.     
  117.     if direction is "none" then
  118.         --nothin but us chickens in here
  119.     else
  120.         if direction = "up" then
  121.             set currentDuration of pStairCaseRecord to (currentDuration of pStairCaseRecord) + (stepSize of pParameters)
  122.         else if direction = "down" then
  123.             set currentDuration of pStairCaseRecord to (currentDuration of pStairCaseRecord) - (stepSize of pParameters)
  124.             if currentDuration of pStairCaseRecord < 1 then set currentDuration of pStairCaseRecord to 1
  125.         else
  126.             error "direction must be up, down, or none"
  127.         end if
  128.         iInitializeResponseHistory()
  129.     end if
  130.     (*     on error
  131.             error "shiftup"
  132.         end try *)
  133. end iHandleShift